﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlarmManagePlatform.Forms
{
    public partial class CollectTerminalForm : RelationsLMP.Control.Form.MetroDemoForms
    {
        public Model.DB.tb_DataCollectTerminalInfo DataCollectTerminalInfo { get; set; }
        public CollectTerminalForm()
        {
            InitializeComponent();

            okReturnToolbar21.Event_OKClick += OkReturnToolbar21_Event_OKClick;
            okReturnToolbar21.Event_ReturnClick += OkReturnToolbar21_Event_ReturnClick;

            DataCollectTerminalInfo = new Model.DB.tb_DataCollectTerminalInfo();
        }

        public void ModifyInfo(Model.DB.tb_DataCollectTerminalInfo temp)
        {
            DataCollectTerminalInfo.Id = temp.Id;
            DataCollectTerminalInfo.Name = temp.Name;
            DataCollectTerminalInfo.IMEI = temp.IMEI;

            txtName.Text = temp.Name;
            txtIMEI.Text = temp.IMEI;
        }

        private void OkReturnToolbar21_Event_OKClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtName.Text))
            {
                txtName.Focus();
                MessageBox.Show(this, "【名称】不能为空！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (string.IsNullOrWhiteSpace(txtIMEI.Text))
            {
                txtIMEI.Focus();
                MessageBox.Show(this, "【IMEI】不能为空！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            if (new DataAccess.tb_DataCollectTerminalInfo().CheckIsExist(txtName.Text, txtIMEI.Text, DataCollectTerminalInfo.Id))
            {
                txtName.Focus();
                MessageBox.Show(this, "该【名称】中【IMEI】已存在！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DataCollectTerminalInfo = new Model.DB.tb_DataCollectTerminalInfo();
            DataCollectTerminalInfo.Name = txtName.Text;
            DataCollectTerminalInfo.IMEI = txtIMEI.Text;

            this.DialogResult = DialogResult.OK;
        }
        private void OkReturnToolbar21_Event_ReturnClick(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
